function $(selector) {
    return document.querySelector(selector)
}


function $$(selector) {
    return document.querySelectorAll(selector)
}

const size_info = {
    easy: { size: 9, side: 70 },
    plain: { size: 13, side: 55 },
    hard: { size: 19, side: 40 }
}

function init_map(mode) {
    const map = []
    for (let i = 0; i < size_info[mode].size; i++) {
        const list = new Array(size_info[mode].size)
        map.push(list.fill(0))
    }
    return map
}



function is_over(map) {
    for (let row = 0; row < map.length - 4; row++) {
        for (let col = 0; col < map.length; col++) {
            if (is_same(row, col)) {
                return map[row][col]
            }
        }
    }
    return false

    function is_same(row, col) {
        const cur_piece = map[row][col]

        if (cur_piece === 0) return false;
        // 从左往右
        if (cur_piece === map[row][col + 1]
            && cur_piece === map[row][col + 2]
            && cur_piece === map[row][col + 3]
            && cur_piece === map[row][col + 4]) {
            return true
            // 从上往下
        } else if (cur_piece === map[row + 1][col]
            && cur_piece === map[row + 2][col]
            && cur_piece === map[row + 3][col]
            && cur_piece === map[row + 4][col]) {
            return true
            // 从左上往右下
        } else if (cur_piece === map[row + 1][col + 1]
            && cur_piece === map[row + 2][col + 2]
            && cur_piece === map[row + 3][col + 3]
            && cur_piece === map[row + 4][col + 4]) {
            return true
            // 从右上到左下
        } else if (cur_piece === map[row + 1][col - 1]
            && cur_piece === map[row + 2][col - 2]
            && cur_piece === map[row + 3][col - 3]
            && cur_piece === map[row + 4][col - 4]) {
            return true
        }
        return false
    }
}

export { $, $$, size_info, is_over, init_map }